package com.hrt.datasender.datadao.model;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Random;

import com.btcode.common.StringUtil;
import com.btcode.exception.MsgException;
import com.btcode.orm.model.IDomainField;
import com.btcode.orm.model.IField;
import com.btcode.orm.model.IModelAddition;
import com.btcode.orm.relation.ex.IRelation;

public class BdS60RtModelAddition implements IModelAddition<BdS60RtModel>, Serializable {

    private static Random random = new Random();

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    @Override
    public void generateDefaultValue(BdS60RtModel model) {

        if (model.getDatatime() == null) {
            throw new MsgException("DataTime不能为空");
        }

        if (model.getCreatetime() == null) {
            model.setCreatetime(new Date());
        }

        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss");

        if (StringUtil.isEmpty(model.getDataId())) {
            String dataId = sf.format(model.getDatatime()) + "_" + model.getParamCodeBus() + "_" + random.nextInt();
            model.setDataId(dataId);
        }

        if (StringUtil.isEmpty(model.getDatatimeText())) {
            String dataTimeText = sf.format(model.getDatatime());
            model.setDatatimeText(dataTimeText);
        }

        if (StringUtil.isEmpty(model.getCreatetimeText())) {
            String dataTimeText = sf.format(model.getCreatetime());
            model.setCreatetimeText(dataTimeText);
        }

    }

    @Override
    public void initField(List<IField> fields) {
        // TODO Auto-generated method stub

    }

    @Override
    public void initRelations(List<IRelation> relations) {
        // TODO Auto-generated method stub

    }

    @Override
    public void initDomainField(List<IDomainField> domainFields) {
        // TODO Auto-generated method stub

    }

    @Override
    public void beforeCreate(BdS60RtModel model) {
        // TODO Auto-generated method stub

    }

    @Override
    public void afterCreate(BdS60RtModel model) {
        // TODO Auto-generated method stub

    }

    @Override
    public void beforeUpdate(BdS60RtModel model) {
        // TODO Auto-generated method stub

    }

    @Override
    public void afterUpdate(BdS60RtModel model) {
        // TODO Auto-generated method stub

    }

    @Override
    public void beforeDelete(BdS60RtModel model) {
        // TODO Auto-generated method stub

    }

    @Override
    public void afterDelete(BdS60RtModel model) {
        // TODO Auto-generated method stub

    }

}
